using UnityEngine;
using System.Collections;

public class MouseLook : MonoBehaviour {
	public enum RotationAxes{
		MouseXAndY=0,
		MouseX=1,
		MouseY=2
	}

	public RotationAxes axes=RotationAxes.MouseXAndY;

	public float sensitivityHor=9f;
	public float sensitivityVert=9f;
	public float miniVert=-45f;
	public float maxivert=45f;

	private float rotationX=0;
	private float rotationY=0;

	void Start () {
		Rigidbody body = GetComponent<Rigidbody> ();
		if (body != null) {
			body.freezeRotation=true;
		}
	}
	
	void Update () {
		if (axes == RotationAxes.MouseX) {
			transform.Rotate (0, Input.GetAxis ("Mouse X") * sensitivityHor, 0);
		} else if (axes == RotationAxes.MouseY) {
			rotationX -= Input.GetAxis ("Mouse Y") * sensitivityVert;
			rotationX = Mathf.Clamp (rotationX, miniVert, maxivert);

			rotationY=transform.localEulerAngles.y;

			transform.localEulerAngles=new Vector3(rotationX,rotationY,0);
		} else {
			rotationX-=Input.GetAxis("Mouse Y")*sensitivityVert;
			rotationX = Mathf.Clamp (rotationX, miniVert, maxivert);

			float delta=Input.GetAxis("Mouse X")*sensitivityHor;
			rotationY=transform.localEulerAngles.y+delta;

			transform.localEulerAngles=new Vector3(rotationX,rotationY,0);

		}
	}
}
